/*
 * @(#)LocatorHandle.java
 *
 * Copyright (c) 1996-2010 by the original authors of JHotDraw and all its
 * contributors. All rights reserved.
 *
 * You may not use, copy or modify this file, except in compliance with the 
 * license agreement you entered into with the copyright holders. For details
 * see accompanying license terms.
 */

package org.jhotdraw.draw.handle;

import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.Point2D;

import org.jhotdraw.draw.Figure;
import org.jhotdraw.draw.locator.Locator;

/**
 * A LocatorHandle implements a Handle by delegating the location requests to a
 * Locator object.
 * 
 * @see Locator
 * 
 * @author Werner Randelshofer
 * @version $Id: LocatorHandle.java 717 2010-11-21 12:30:57Z rawcoder $
 */
public abstract class LocatorHandle extends AbstractHandle {
	private Locator locator;

	/**
	 * Initializes the LocatorHandle with the given Locator.
	 */
	public LocatorHandle(Figure owner, Locator l) {
		super(owner);
		locator = l;
	}

	public Point2D.Double getLocationOnDrawing() {
		return locator.locate(getOwner());
	}

	public Point getLocation() {
		return view.drawingToView(locator.locate(getOwner()));
	}

	@Override
	protected Rectangle basicGetBounds() {
		Rectangle r = new Rectangle(getLocation());
		int h = getHandlesize();
		r.x -= h / 2;
		r.y -= h / 2;
		r.width = r.height = h;
		return r;
	}
}
